#include <rtdevice.h>
#include "at32f403a_407.h"



spi_init_type spi_init_struct;

/**
  * @brief  spi configuration.
  * @param  none
  * @retval none
  */
static void spi_config(void)
{
  crm_periph_clock_enable(CRM_SPI1_PERIPH_CLOCK, TRUE);
  crm_periph_clock_enable(CRM_SPI3_PERIPH_CLOCK, TRUE);
  spi_default_para_init(&spi_init_struct);
  spi_init_struct.transmission_mode = SPI_TRANSMIT_HALF_DUPLEX_TX;
  spi_init_struct.master_slave_mode =SPI_MODE_MASTER;
  spi_init_struct.mclk_freq_division = SPI_MCLK_DIV_8;
  spi_init_struct.first_bit_transmission = SPI_FIRST_BIT_MSB;
  spi_init_struct.frame_bit_num = SPI_FRAME_8BIT;
  spi_init_struct.clock_polarity = SPI_CLOCK_POLARITY_LOW;
  spi_init_struct.clock_phase = SPI_CLOCK_PHASE_2EDGE;
  spi_init_struct.cs_mode_selection = SPI_CS_SOFTWARE_MODE;
  spi_init(SPI1, &spi_init_struct);

  spi_init_struct.transmission_mode = SPI_TRANSMIT_HALF_DUPLEX_RX;
  spi_init_struct.master_slave_mode =SPI_MODE_SLAVE;
  spi_init(SPI3, &spi_init_struct);

//  nvic_irq_enable(SPI1_IRQn, 0, 0);
//  nvic_irq_enable(SPI2_I2S2EXT_IRQn, 0, 0);
//  spi_i2s_interrupt_enable(SPI1, SPI_I2S_TDBE_INT, TRUE);
//  spi_i2s_interrupt_enable(SPI2, SPI_I2S_RDBF_INT, TRUE);

  spi_enable(SPI3, TRUE);
  spi_enable(SPI1, TRUE);
}

void _spi_data_trans(int argc,char **argv)
{
		rt_uint8_t	val = atoi(argv[2]);
		spi_i2s_data_transmit(SPI1, val);
	
		rt_kprintf("%d was sent !",val);
}




















